package ycl.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ycl.system.req.SysPermissionReq;
import ycl.common.result.Result;
import ycl.common.base.controller.BaseController;
import ycl.common.models.base.A;
import ycl.system.entity.SysPermission;
import ycl.system.res.SysPermissionRes;
import ycl.system.service.SysPermissionService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-03-03 11:43:56
 */
@RestController
@RequestMapping("/sys-permission")
@Api(tags = "权限")
public class SysPermissionController extends BaseController<SysPermission, SysPermissionReq, SysPermissionRes> {

	@Resource
	private SysPermissionService sysPermissionService;

	@GetMapping("selectByUserId")
	@ApiOperation("根据id查询用户所有权限")
	public Result<List<SysPermission>> selectByUserId(@RequestParam("userId") Long userId) {
		List<SysPermission> list = sysPermissionService.selectByUserId(userId);
		return Result.success(list);
	}


	@Override
	public Result<Page<SysPermissionRes>> pageList(HttpServletRequest request, SysPermission sysPermission) {
		return Result.success(sysPermissionService.pageList(request, sysPermission, SysPermissionRes.class));
	}

	@Override
	public <E extends SysPermissionReq> Result<A> save(HttpServletRequest request, @RequestBody @Valid E e) {
		sysPermissionService.save(request, e, SysPermission.class);
		return Result.success();
	}

	@Override
	public <E extends SysPermissionReq> Result<A> update(HttpServletRequest request, @RequestBody @Valid E e) {
		sysPermissionService.update(request, e, SysPermission.class);
		return Result.success();
	}
}

